package com.ruoyi.web.controller.agency;

import com.ruoyi.system.entity.AgencyTask;
import com.ruoyi.system.service.AgencyTaskService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 待办任务表(AgencyTask)表控制层
 *
 * @author makejava
 * @since 2022-12-05 21:37:58
 */
@RestController
@RequestMapping("agencyTask")
public class AgencyTaskController {
    /**
     * 服务对象
     */
    @Resource
    private AgencyTaskService agencyTaskService;

    /**
     * 分页查询
     *
     * @param agencyTask 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<AgencyTask>> queryByPage(AgencyTask agencyTask, PageRequest pageRequest) {
        return ResponseEntity.ok(this.agencyTaskService.queryByPage(agencyTask, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<AgencyTask> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.agencyTaskService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param agencyTask 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<AgencyTask> add(AgencyTask agencyTask) {
        return ResponseEntity.ok(this.agencyTaskService.insert(agencyTask));
    }

    /**
     * 编辑数据
     *
     * @param agencyTask 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<AgencyTask> edit(AgencyTask agencyTask) {
        return ResponseEntity.ok(this.agencyTaskService.update(agencyTask));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.agencyTaskService.deleteById(id));
    }

}

